﻿using System.Web;

namespace SpiderMaster.AspNet.TradingSystem
{
    public partial class ImageManager
    {
        public class Handler : IHttpHandler
        {
            public void ProcessRequest(HttpContext Context)
            {
                HttpResponse Response = Context.Response;
                HttpRequest Request = Context.Request;

                int ImageId = LinkManager.ReceiveUrlQuery(QueryOperator.ImageId, ImageManager.DefaultValues.IdNullValue);
                if (ImageId != ImageManager.DefaultValues.IdNullValue)
                {
                    // checking if a particular ImageSize was requested in the querystring (otherwise, small is default)
                    ImageSize ImageSize = LinkManager.ReceiveUrlQuery(QueryOperator.ImageSize, ImageSize.Small);

                    ImageType ImageType = LinkManager.ReceiveUrlQuery(QueryOperator.ImageType, ImageType.UnSpecified);

                    if (ImageType != ImageManager.ImageType.UnSpecified)
                        Response.Redirect(ImageManager.GetFilePath(ImageId, ImageType, ImageSize, true), true);
                }
            }
            public bool IsReusable { get { return true; } }
        }
    }
}